<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>manage</title>
    <script src="__LAYUI__/layui.js"></script>
    <link href="__LAYUI__/css/layui.css" rel="stylesheet"/>
</head>
<body>


<div style="height: 40px;text-align: center;line-height: 40px">
    <div style="float: right">
        <button class="layui-btn layui-btn-normal" id="staffInsert">新增</button>
    </div>
</div>


<table id="table" lay-filter="text"></table>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>

<script>
    layui.use(['table', 'jquery', 'layer'], function () {
        var table = layui.table,
            $ = layui.$;
        table.render({
            elem: '#table'
            ,
            id: 'idTest'
            ,
            height: 370
            ,
            page: true
            ,
            limit: 10
            ,
            skin: 'line'
            ,
            even: true
            ,
            size: 'lg'
            ,
            cols: [[
                {field: 'Id', title: 'ID', width: 50}
                , {field: 'username', title: '用户名', width: 200}
                , {field: 'level', title: '等级', width: 200}
                , {field: 'times', title: '登陆次数', width: 200}
                , {field: 'date', title: '最后登录时间', width: 200}
                , {fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo'}
            ]]
            ,
            url: '/index/login/selUser'
            , response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , statusCode: 1 //成功的状态码，默认：0
            }
//            ,url:'https://127.0.0.1/index/Database/find'
        });
        $('#staffInsert').click(function () {
            var layer = layui.layer;
            layer.open({
                type: 2,
                offset: '0px',
                title: '新增用户',
                scrollbar: false,
                resize: false,
                area: ['600px', '300px'],
                shadeClose: true,
                content: ['/index/Adm/insertUser/', 'no'],
            });
        });


        table.on('tool(text)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;

            if (layEvent === 'edit') {
            } else if (layEvent === 'del') {
                layer.open({
                    type: 0,
                    content: '确定删除?',
                    yes: function (index, layero) {
                        $.ajax({
                            type: 'post',
                            url: '/index/login/delUser/ ',
                            data: {
                                'username': data.username
                            },
                            success: function (result) {
                                if (result.code) {
                                    layer.msg('删除成功', {
                                        icon: 1,
                                        time: 3000 //2秒关闭（如果不配置，默认是3秒）
                                    });
                                }

                                table.reload('idTest', {});
                            }
                        });

                        layer.close(index);
                    }

                });
            }
        })
    });
</script>


</body>
</html>